package org.jmhome.blog.service.impl;

import org.jmhome.blog.model.AttachmentFile;
import org.jmhome.blog.service.AbstractJpaDaoService;
import org.jmhome.blog.service.FileService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service("fileService")
public class FileServiceImpl extends AbstractJpaDaoService implements
		FileService {

	/**
	 * @see org.jmhome.blog.service.FileService#insertFile(org.jmhome.blog.model.AttachmentFile)
	 */
	@Override
	public void insertFile(AttachmentFile file) {
		getJpaTemplate().persist(file);
	}

	/**
	 * @see org.jmhome.blog.service.FileService#deleteFile(org.jmhome.blog.model.AttachmentFile)
	 */
	@Override
	public void deleteFile(AttachmentFile file) {
		getJpaTemplate().remove(file);
	}

	/**
	 * @see org.jmhome.blog.service.FileService#deleteFile(java.lang.Integer)
	 */
	@Override
	public void deleteFile(Integer fileSeq) {
		AttachmentFile file = getFile(fileSeq);
		getJpaTemplate().remove(file);
	}

	/**
	 * @see org.jmhome.blog.service.FileService#getFile(java.lang.Integer)
	 */
	@Override
	public AttachmentFile getFile(Integer fileSeq) {
		return getJpaTemplate().find(AttachmentFile.class, fileSeq);
	}

}
